package com.example.administrator.nurse.present;

import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.nurse.R;
import com.example.administrator.nurse.base.BaseActivity;
import com.example.administrator.nurse.feature.FeatureActivity;
import com.example.administrator.nurse.model.adapter.CommonAdapter;
import com.example.administrator.nurse.model.adapter.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huhaichao on 2017/1/12.
 */

public class AuxiliaryToolsActivity extends BaseActivity {
    GridView gridView;
    ArrayList<String> titleList;
    ArrayList<Integer> imgList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        configCommonHeader(AuxiliaryToolsActivity.this, "辅助工具", 1);
        initView();
    }

    @Override
    protected int setLayotId() {
        return R.layout.auxiliary_tools_main;
    }

    @Override
    protected void onFailure(int requestCode, Object object, String errorMsg) {

    }

    @Override
    protected void onSuccess(int requestCode, Object object, String response) {

    }

    private void initView() {
        titleList = getTileList();
        imgList = getImgList();
        GridAdapter adapter = new GridAdapter(titleList, R.layout.main_grid_item, AuxiliaryToolsActivity.this);
        gridView = (GridView) findViewById(R.id.bottonLine);
        gridView.setAdapter(adapter);
        gridView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Log.d("nurse", "---onItemSelected---" + position);
                itemSelected(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.d("nurse", "---onItemClick---" + position);
                itemSelected(position);
            }
        });

    }

    private void itemSelected(int position) {
        switch (position) {
            case 0:

                break;
            case 1:

                break;
            case 2:

                break;
            case 3:

                break;
            case 4:

                break;
            case 5:

                break;
            case 6:

                break;
            case 7:

                break;
            case 8:

                break;
        }
    }

    private ArrayList<String> getTileList() {
        ArrayList<String> titleList = new ArrayList<>();
        Resources res = getResources();
        titleList.add("护士笔记");
        titleList.add("个人信息");
        titleList.add("个人备忘");
        titleList.add("公式查询");
        titleList.add("常见症状");
        titleList.add("护理助手");
        titleList.add("个人收藏");
        titleList.add("工作统计");
        titleList.add("待定工具");
        return titleList;
    }

    private ArrayList<Integer> getImgList() {
        ArrayList<Integer> imgList = new ArrayList<>();
        imgList.add(R.mipmap.execution_of_doctors_order);
        imgList.add(R.mipmap.sign_entry);
        imgList.add(R.mipmap.ward_inspection);
        imgList.add(R.mipmap.search_cost);
        imgList.add(R.mipmap.medical_examination_report);
        imgList.add(R.mipmap.liquid_distribution_management);
        imgList.add(R.mipmap.nursing_assessment);
        imgList.add(R.mipmap.job_account);
        imgList.add(R.mipmap.assistant_tool);
        return imgList;
    }

    class GridAdapter extends CommonAdapter {

        public GridAdapter(List mDatas, int layoutId, Context context) {
            super(mDatas, layoutId, context);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = View.inflate(AuxiliaryToolsActivity.this, R.layout.main_grid_item, null);
            }
            TextView textView = (TextView) ViewHolder.get(R.id.main_item, convertView);
            ImageView img = (ImageView) ViewHolder.get(R.id.grid_img, convertView);
            img.setImageResource(imgList.get(position));
            textView.setText(titleList.get(position));
            return convertView;
        }
    }
}
